package com.aaa.springboot_rbac.controller;

import com.aaa.springboot_rbac.entity.Student;
import com.aaa.springboot_rbac.service.StudentService;
import com.aaa.springboot_rbac.util.Page;
import com.aaa.springboot_rbac.util.Result;
import com.aaa.springboot_rbac.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @FileName: StudentController
 * @Description:
 * @Author: 张钰哲
 * @CreateTime: 2025/8/22 15:53
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
private StudentService  studentService;
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<Student> page){
        PageInfo pageInfo = studentService.queryByPage(page);
        return ResultUtil.success(pageInfo);
    }
    @GetMapping("queryById")
    public Result queryById(Integer stuId){
        Student student = studentService.queryById(stuId);
        return ResultUtil.success(student);
    }
    @PostMapping("add")
    public Result add(@RequestBody Student student){
        int add = studentService.add(student);
        return ResultUtil.success(add);
    }
    @PostMapping("update")
    public Result update(@RequestBody Student student){
        int update = studentService.update(student);
        return ResultUtil.success(update);
    }
    @DeleteMapping("deleteById")
    public Result delete(Integer stuId){
        int i = studentService.deleteById(stuId);
        return ResultUtil.success(i);
    }

}
